<?php
error_reporting("E_ALL");ini_set("display_errors", 1);
$getdata=$_REQUEST;
if(empty($getdata))$getdata=$_POST?$_POST:$_GET;
$type=empty($getdata['type'])?'':$getdata['type'];
include("include/function.php");
//header("content-Type: application/json; charset=utf-8");
$config = include("config.php");
include("include/".$config['DB_TYPE'].".class.php");
$db = new db;
$db->connect($config['DB_HOST'],$config['DB_USER'],$config['DB_PWD'],$config['DB_NAME'], $config['DB_PCONNECT']);
  
$page = empty($getdata['page'])?1:$getdata['page'];
$id = empty($getdata['id'])?0:$getdata['id'];
$length=10;
$start=($page-1)*$length;
$end =$start+$length;
$totalpage=266;
$post=[];
$post['draw']='2';
$post['start']=$start;
$post['length']=$length;
$post['token']='e3220cc48fc44cfc81897b1069d419ac.SC_EDU_WEB';
$post['unitId']='';
$post['condKey']='teacherName';
$post['condValue']='';
$url='https://hs_kitchen.xyt360.com.cn/kitchen/web/teacher/getListByPaginate';
$result = http_post($url,http_build_query($post),array('Content-Type: application/x-www-form-urlencoded'),'rmbUser=true; userName=admink');
$content=json_decode($result,1);$insert=0;
if(!empty($content['data'])){
    foreach($content['data'] as $k=>$v){
        //if($v['inSchoolYear']<=2018)continue;
        $id=$v['id']+100000;
        $check = $db->get_one("select `id` from student_hs where `id`='".$id."'");
        if(empty($check)){
            $data=[];
            $data['id']=$id;
            $data['unitName']=$v['unitName'];
            $data['uuid']=$v['uuid'];
            $data['patriarchUuid']=$v['userId'];
            //$data['']=$v['idcode'];
            $data['mobile']=$v['phone'];
            $data['studentName']=$v['name'];
            $data['unitId']=$v['unitId'];
            $data['status']=$v['status'];
            $data['createTime']=$v['createtime'];
            //$data['']=$v['updatetime'];
            
            $sql = "insert into student_hs(`".implode('`,`',array_keys($data))."`) values('".implode("','",$data)."');";
            $res=$db->query($sql);if(!$res)exit;$insert++;
        }
        echo $v['id'].'=>'.$v['name']."\n<br>";
    }
    $page++;
}else{print_r($content);
    $id++;sleep(3);
}
if($page>=$totalpage){echo 'over';exit;}
$log = $id.'导入成功,新增：'.$insert.'条';
echo $log.'<script>location.href="?page='.$page.'&id='.$id.'";</script>';

//echo count($sqlarr)."\n";
//echo implode(";\n",$sqlarr);
?>